<?php ob_start();
session_start(); // on relaye la session 
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
		$enregistrer = $_SESSION["is_registered"];
}else{
	header("location:../../menu.php"); // redirection en cas d'echec
}
	require_once('../../Connections/microassur.php'); 
	require_once('../../utils/fonctions.php');	
	//require_once('../inclure.php');
	$message = '';
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if( isset($_POST['Raison_sociale']) && empty($_POST['Raison_sociale']) ){
	$message = colorer("Vous devez saisir la RAISON SOCIALE.","false");
}/*elseif(isset($_POST['Raison_sociale']) && caracteres_interdits($_POST['Raison_sociale'])==1){
	$message = colorer("La raison sociale saisie comporte des caractères spéciaux interdits.","false");
}*/else{
	if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
	  $updateSQL = sprintf("UPDATE personne SET Raison_sociale=%s WHERE Identifiant_personne=%s",
						   GetSQLValueString($_POST['Raison_sociale'], "text"),
						   GetSQLValueString($_POST['Identifiant_personne'], "int"));
	
	  mysql_select_db($database_microassur, $microassur);
	  mysql_query("START TRANSACTION");
	  $Result1 = mysql_query($updateSQL, $microassur) or die(mysql_error());
	  if($Result1){
	    mysql_query("commit");
		$message = colorer("La modification de ce partenaire est prise en compte.","true");
	  }else{
		mysql_query("rollback");
		$message = colorer("Problème modification partenaire, contacter la DSI.","false");
	  }
	}
}
$colname_rs_mod = "-1";
if (isset($_GET['Identifiant_personne'])) {
  $colname_rs_mod = $_GET['Identifiant_personne'];
}
mysql_select_db($database_microassur, $microassur);
$query_rs_mod = sprintf("SELECT * FROM personne WHERE Identifiant_personne = %s", GetSQLValueString($colname_rs_mod, "int"));
$rs_mod = mysql_query($query_rs_mod, $microassur) or die(mysql_error());
$row_rs_mod = mysql_fetch_assoc($rs_mod);
$totalRows_rs_mod = mysql_num_rows($rs_mod);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
			<title>Modification partenaire</title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
	</head>
<body>
<div id="sf_menu1">
	<h3>Partenaire</h3>
<?php
	if(isset($_GET['msg']) && $_GET['msg']=='insert')
		$message = colorer("Le partenaire est créé.","true");

	if(isset($message) && !empty($message)){
		echo $message;
	}
	$nommodule="Gestion partenaire";
	//$nommodule2="Liste des partenaires";
	$nom_module_saisie="Détail partenaire";
?>
</div>
<div class="cleared"></div>

<div class="corps1">
<!--/***************************************/-->

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
	<div class="imgleft"></div>
	<div class="imgmiddle">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
	<div class="formulaire">
  <table class="tabform">
	<input type="hidden" name="Type_personne" value="<?php echo htmlentities($row_rs_mod['Type_personne'], ENT_COMPAT, 'utf-8'); ?>" />
    <input type="hidden" name="Etat_personne" value="<?php echo htmlentities($row_rs_mod['Etat_personne'], ENT_COMPAT, 'utf-8'); ?>" />
    <tr>
      <td class="td0">RAISON SOCIALE</td>
      <td><input class="resize_2" type="text" name="Raison_sociale" value="<?php  if(isset($_POST['Raison_sociale'])){ echo remind_text('Raison_sociale'); }else{ echo htmlentities($row_rs_mod['Raison_sociale'], ENT_COMPAT, 'utf-8');} ?>" size="32" maxlength="30" /></td>
    </tr>
  </table>
    </div>
</div>
<div class="imgright"></div>				
<div class="cleared"></div>

<div class="bt1">
	<a href="index.php">
	<span class="btleft"></span>
    <span class="btmiddle">Retour</span>
    <span class="btright"></span>
    </a>
</div>

<div class="bt">
	<a href="../communication/index.php?Identifiant_personne=<?php echo $row_rs_mod['Identifiant_personne']; ?>">
	<span class="btleft"></span>
    <span class="btmiddle">Communication</span>
    <span class="btright"></span>
    </a>
</div>
<div class="bt">
	<a href="../adresse/index.php?Identifiant_personne=<?php echo $row_rs_mod['Identifiant_personne']; ?>">
	<span class="btleft"></span>
    <span class="btmiddle">Adresse</span>
    <span class="btright"></span>
    </a>
</div>
<?php //$idRole = getIdRole($database_microassur, $microassur, $row_rs_mod['Identifiant_personne']); ?>
<!--div class="bt">
	<a href="rattacherOffre.php?Identifiant_role=<?php //echo $idRole; ?>">
	<span class="btleft"></span>
    <span class="btmiddle">Rattacher à une Offre</span>
    <span class="btright"></span>
    </a>
</div-->
<div class="bt">
	<a href="index.php">
    	<span class="btleft"></span>
        <span class="btmiddle">Annuler</span>
        <span class="btright"></span>
    </a>
</div>
<div class="bt">
	<span class="btleft"></span>
    <input type="submit" name="Valider" value="Valider" class="resizeall btmiddle"/>
    <span class="btright"></span>
</div>
    
<div class="cleared"></div>

  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="Identifiant_personne" value="<?php echo $row_rs_mod['Identifiant_personne']; ?>" />
</form>
 </div>
</body>
</html>
<?php
mysql_free_result($rs_mod);
?>
<?php  ob_end_flush(); ?>